home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / fileve1a / idd_main.frm < prev   
Text File  |  1999-09-23  |  7KB  |  224 lines

  1. VERSION 5.00
  2. Begin VB.Form IDD_Main 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "File Logger"
  5.    ClientHeight    =   3660
  6.    ClientLeft      =   45
  7.    ClientTop       =   330
  8.    ClientWidth     =   4020
  9.    Icon            =   "IDD_Main.frx":0000
  10.    LinkTopic       =   "Form1"
  11.    MaxButton       =   0   'False
  12.    MinButton       =   0   'False
  13.    ScaleHeight     =   3660
  14.    ScaleWidth      =   4020
  15.    StartUpPosition =   2  'CenterScreen
  16.    Begin VB.CheckBox IDCK_StaggerOutput 
  17.       Caption         =   "Stagger Output"
  18.       Height          =   255
  19.       Left            =   2040
  20.       TabIndex        =   7
  21.       Top             =   2520
  22.       Value           =   1  'Checked
  23.       Width           =   1935
  24.    End
  25.    Begin VB.TextBox IDE_SearchString 
  26.       Height          =   285
  27.       Left            =   120
  28.       TabIndex        =   5
  29.       Text            =   "*.*"
  30.       Top             =   2760
  31.       Width           =   1695
  32.    End
  33.    Begin VB.CommandButton IDCM_Exit 
  34.       Caption         =   "E&xit"
  35.       Height          =   375
  36.       Left            =   2640
  37.       TabIndex        =   4
  38.       Top             =   3120
  39.       Width           =   1215
  40.    End
  41.    Begin VB.CommandButton IDCM_Execute 
  42.       Caption         =   "&Execute"
  43.       Default         =   -1  'True
  44.       Height          =   375
  45.       Left            =   120
  46.       TabIndex        =   3
  47.       Top             =   3120
  48.       Width           =   1215
  49.    End
  50.    Begin VB.CheckBox IDCK_Recursive 
  51.       Caption         =   "Recurse Directories"
  52.       Height          =   255
  53.       Left            =   2040
  54.       TabIndex        =   2
  55.       Top             =   2760
  56.       Value           =   1  'Checked
  57.       Width           =   1935
  58.    End
  59.    Begin VB.DirListBox IDDIR_Local 
  60.       Height          =   1890
  61.       Left            =   120
  62.       TabIndex        =   1
  63.       Top             =   120
  64.       Width           =   3735
  65.    End
  66.    Begin VB.DriveListBox IDDRIVE_Local 
  67.       Height          =   315
  68.       Left            =   120
  69.       TabIndex        =   0
  70.       Top             =   2160
  71.       Width           =   3735
  72.    End
  73.    Begin VB.Label IDL_SearchString 
  74.       AutoSize        =   -1  'True
  75.       Caption         =   "Search String"
  76.       Height          =   195
  77.       Left            =   120
  78.       TabIndex        =   6
  79.       Top             =   2520
  80.       Width           =   960
  81.    End
  82. End
  83. Attribute VB_Name = "IDD_Main"
  84. Attribute VB_GlobalNameSpace = False
  85. Attribute VB_Creatable = False
  86. Attribute VB_PredeclaredId = True
  87. Attribute VB_Exposed = False
  88. Option Explicit
  89. Dim LevelsDeep As Integer
  90.  
  91. Private Sub Form_Load()
  92.     LevelsDeep = 0
  93. End Sub
  94.  
  95. Private Sub IDCM_Execute_Click()
  96. Dim LocalPath As String
  97. Dim LogFileName As String
  98. Dim PrintString As String
  99. Dim FileCount As Integer
  100. Dim DirCount As Integer
  101.     
  102.     Me.MousePointer = vbHourglass
  103.     If Right(IDDIR_Local.path, 1) = "\" Then
  104.         LocalPath = IDDIR_Local.path
  105.     Else
  106.         LocalPath = IDDIR_Local.path & "\"
  107.     End If
  108.  
  109.     LogFileName = Environ("TEMP") & "\" & App.Title & ".log"
  110.  
  111.     Open LogFileName For Output As #1
  112.     PrintString = "File Log for Directory: " & Mid(LocalPath, 1, Len(LocalPath) - 1)
  113.     If IDCK_Recursive.Value = vbChecked Then
  114.         PrintString = PrintString & " (Recursing Sub Directories)"
  115.     End If
  116.     Print #1, PrintString
  117.     Print #1, Now
  118.     Print #1,
  119.     
  120.     Call FindFiles(LocalPath, IDE_SearchString, FileCount, DirCount, CInt(IDCK_Recursive.Value) * -1)
  121.     
  122.     Close #1
  123.     
  124.     Call Shell("notepad " & LogFileName, vbMaximizedFocus)
  125.     Me.MousePointer = vbDefault
  126.     
  127. End Sub
  128.  
  129. Function FindFiles(path As String, SearchStr As String, FileCount As Integer, DirCount As Integer, Optional ByVal RecurseSubs As Boolean = True)
  130. Dim FileInformation As FILE_INFORMATION
  131. Dim FileName As String   ' Walking filename variable.
  132. Dim DirName As String    ' SubDirectory Name.
  133. Dim dirNames() As String ' Buffer for directory name entries.
  134. Dim nDir As Integer      ' Number of directories in this path.
  135. Dim i As Integer         ' For-loop counter.
  136. Dim VersionInfo As String
  137. Dim LastDir As String
  138. Dim Spaces As String
  139. Dim Count As Integer
  140. Const SpaceChar As String = vbTab
  141.  
  142.  
  143.     On Error GoTo sysFileERR
  144.     If Right(path, 1) <> "\" Then path = path & "\"
  145.     ' Search for subdirectories.
  146.     nDir = 0
  147.     ReDim dirNames(nDir)
  148.     DirName = Dir(path, vbDirectory Or vbHidden)  ' Even if hidden.
  149.     Do While Len(DirName) > 0
  150.         ' Ignore the current and encompassing directories.
  151.         If (DirName <> ".") And (DirName <> "..") Then
  152.             ' Check for directory with bitwise comparison.
  153.             If GetAttr(path & DirName) And vbDirectory Then
  154.                dirNames(nDir) = DirName
  155.                DirCount = DirCount + 1
  156.                nDir = nDir + 1
  157.                ReDim Preserve dirNames(nDir)
  158.             End If
  159. sysFileERRCont:
  160.         End If
  161.         DirName = Dir()  ' Get next subdirectory.
  162.     Loop
  163.     
  164.     ' Search through this directory and sum file sizes.
  165.     FileName = Dir(path & SearchStr, vbNormal Or vbHidden Or vbSystem Or vbReadOnly)
  166.     While Len(FileName) <> 0
  167.         FindFiles = FindFiles + FileLen(path & FileName)
  168.         FileCount = FileCount + 1
  169.         Call GetFileInformation(path & FileName, FileInformation)
  170.         Spaces = ""
  171.         If IDCK_StaggerOutput.Value = vbChecked Then
  172.             If LevelsDeep > 0 Then
  173.                 For Count = 1 To LevelsDeep
  174.                     Spaces = Spaces & SpaceChar
  175.                 Next Count
  176.             End If
  177.         Else
  178.             Spaces = ""
  179.         End If
  180.         If FileInformation.cDirectory <> LastDir Then
  181.             Print #1,
  182.             Print #1, Spaces & "Directory: --> " & FileInformation.cDirectory
  183.             Print #1, Spaces & "-----------------------------------------------------------------------"
  184.             LastDir = FileInformation.cDirectory
  185.         End If
  186.         If FileInformation.nVerMajor <> 0 Or FileInformation.nVerMinor <> 0 Or FileInformation.nVerRevision <> 0 Then
  187.             VersionInfo = " - Version:" & FileInformation.nVerMajor & "." & FileInformation.nVerMinor & "." & FileInformation.nVerRevision
  188.         Else
  189.             VersionInfo = ""
  190.         End If
  191. '        Spaces = Spaces & SpaceChar
  192.         Print #1, Spaces & FileInformation.cFilename & " - Modify Date:" & Format(FileInformation.dtLastModifyTime, "mm/dd/yyyy HH:MM AMPM") & " - File Size:" & FileInformation.nFileSize & " bytes" & VersionInfo
  193.         FileName = Dir()  ' Get next file.
  194.     Wend
  195.  
  196.     ' If there are sub-directories..
  197.     If nDir > 0 And RecurseSubs = True Then
  198.         ' Recursively walk into them
  199.         For i = 0 To nDir - 1
  200.             LevelsDeep = LevelsDeep + 1
  201.             FindFiles = FindFiles + FindFiles(path & dirNames(i) & "\", SearchStr, FileCount, DirCount)
  202.             LevelsDeep = LevelsDeep - 1
  203.         Next i
  204.     End If
  205.  
  206. AbortFunction:
  207.     Exit Function
  208. sysFileERR:
  209.     If Right(DirName, 4) = ".sys" Then
  210.         Resume sysFileERRCont ' Known issue with pagefile.sys
  211.     Else
  212.         Resume AbortFunction
  213.     End If
  214. End Function
  215.  
  216.  
  217. Private Sub IDCM_Exit_Click()
  218.     Unload Me
  219. End Sub
  220. Private Sub IDDRIVE_Local_Change()
  221.     On Error Resume Next
  222.     IDDIR_Local.path = IDDRIVE_Local.Drive
  223. End Sub
  224.